package bb.lanxing.model.database;

import java.util.List;

import org.json.JSONObject;
import org.litepal.LitePal;

import com.baidu.mapapi.model.LatLng;
import com.github.mikephil.charting.utils.Utils;
import com.umeng.socialize.net.utils.SocializeProtocolConstants;

import android.database.sqlite.SQLiteDatabase;
import android.os.Parcel;
import android.os.Parcelable;

import bb.lanxing.model.data.IBasePOI;
import bb.lanxing.util.JsonUtil;

public class Waypoint extends LitePalTableBase implements IBasePOI, Parcelable {
    public static final Parcelable.Creator<Waypoint> CREATOR = new Parcelable.Creator<Waypoint>() {

        @Override
        public Waypoint[] newArray(int size) {
            return new Waypoint[size];
        }

        @Override
        public Waypoint createFromParcel(Parcel in2) {
            return new Waypoint(in2);
        }
    };
    public static final int TYPE_CHECK = 1;
    public static final int TYPE_WAY = 0;
    private static SQLiteDatabase db;
    private String content;
    private String image;
    private double latitude;
    private double longitude;
    private long lushuId;
    private String title;
    private int type;

    public Waypoint() {
    }

    public Waypoint(JSONObject jSONObject) {
        this.latitude = JsonUtil.getDoubleValue("latitude", jSONObject);
        this.longitude = JsonUtil.getDoubleValue("longitude", jSONObject);
        this.title = JsonUtil.getStringValue("title", jSONObject);
        this.content = JsonUtil.getStringValue("content", jSONObject);
        this.image = JsonUtil.getStringValue(SocializeProtocolConstants.IMAGE, jSONObject);
        this.type = JsonUtil.getIntegerValue("type", jSONObject);
        if (this.latitude == Utils.DOUBLE_EPSILON) {
            this.latitude = JsonUtil.getDoubleValue("lat", jSONObject);
        }
        if (this.longitude == Utils.DOUBLE_EPSILON) {
            this.longitude = JsonUtil.getDoubleValue("lng", jSONObject);
        }
    }

    public Waypoint(Parcel parcel) {
        this.lushuId = parcel.readLong();
        this.latitude = parcel.readDouble();
        this.longitude = parcel.readDouble();
        this.title = parcel.readString();
        this.content = parcel.readString();
        this.image = parcel.readString();
        this.type = parcel.readInt();
    }

    public static List<Waypoint> getByLushuId(long j) {
        String lushuId = String.valueOf(j);
        return LitePal.where("lushuId=?", lushuId).find(Waypoint.class);
    }

    public static void savePoints(List<Waypoint> list) {
        LitePal.saveAll(list);
    }

    public static void deleteByRouteBookId(long j) {
        String lushuId = String.valueOf(j);
        LitePal.deleteAll(Waypoint.class, "lushuId=?", lushuId);
    }

    @Override
    public int describeContents() {
        return 0;
    }

    @Override
    public void writeToParcel(Parcel parcel, int i) {
        parcel.writeLong(this.lushuId);
        parcel.writeDouble(this.latitude);
        parcel.writeDouble(this.longitude);
        parcel.writeString(this.title);
        parcel.writeString(this.content);
        parcel.writeString(this.image);
        parcel.writeInt(this.type);
    }

    public int getType() {
        return this.type;
    }

    public void setType(int i) {
        this.type = i;
    }

    public long getLushuId() {
        return this.lushuId;
    }

    public void setLushuId(long j) {
        this.lushuId = j;
    }

    @Override
    public double getLatitude() {
        return this.latitude;
    }

    @Override
    public void setLatitude(double d) {
        this.latitude = d;
    }

    @Override
    public double getLongitude() {
        return this.longitude;
    }

    @Override
    public void setLongitude(double d) {
        this.longitude = d;
    }

    @Override
    public LatLng getLatLng() {
        return new LatLng(this.latitude, this.longitude);
    }

    @Override
    public void setLatLng(LatLng latLng) {
        setLatitude(latLng.latitude);
        setLongitude(latLng.longitude);
    }

    @Override
    public String getTitle() {
        return this.title;
    }

    @Override
    public void setTitle(String str) {
        this.title = str;
    }

    @Override
    public String getContent() {
        return this.content;
    }

    @Override
    public void setContent(String str) {
        this.content = str;
    }

    @Override
    public String getImage() {
        return this.image;
    }

    @Override
    public void setImage(String str) {
        this.image = str;
    }
}
